//
//  MCFriendViewController.m
//  MicroChat
//
//  Created by Mac on 2018/5/29.
//  Copyright © 2018年 stoneobs.qq.com. All rights reserved.
//

#import "MCFriendViewController.h"
#import "MCFriendTableViewCell.h"
#import "STPopMenuViewController.h"
#import "MCAddFriendSearchViewController.h"
#import "MCOtherPersonViewController.h"
@interface MCFriendViewController ()
@property(nonatomic, strong) NSMutableArray                     *dataSouce;/**< 好友 */
@end

@implementation MCFriendViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"好友";
    [self configSubView];
    // Do any additional setup after loading the view.
}

#pragma mark --subView
- (void)configSubView{
    UIImageView * imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"添加"]];
    [self st_setRightItemWithView:imageView];
    __weak typeof(self) weakSelf =  self;
    UIView * header = [[UIView alloc] initWithFrame:CGRectMake(0, 0, UIScreenWidth, 30)];
    header.backgroundColor = [UIColor whiteColor];
    
    STButton * searchButton = [[STButton alloc] initWithFrame:CGRectMake(15, 15, UIScreenWidth - 30, 35)
                                                        title:@"搜索"
                                                   titleColor:SecendTextColor
                                                    titleFont:16
                                                 cornerRadius:4
                                              backgroundColor:self.tableView.backgroundColor
                                              backgroundImage:nil
                                                        image:[UIImage imageNamed:@"search"]];
    searchButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
    searchButton.titleEdgeInsets = UIEdgeInsetsMake(0, 10, 0, 0);
    [searchButton setClicAction:^(UIButton *sender) {
        [weakSelf onSelctedSerarchButton];
    }];
    [header addSubview:searchButton];
    
    STButton * addButton = [[STButton alloc] initWithFrame:CGRectMake(0, searchButton.bottom, UIScreenWidth , 50)
                                                        title:@"新朋友"
                                                   titleColor:FirstTextColor
                                                    titleFont:16
                                                 cornerRadius:4
                                              backgroundColor:UIColor.whiteColor
                                              backgroundImage:nil
                                                        image:[UIImage imageNamed:@"new_friend"]];
    addButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
    addButton.titleEdgeInsets = UIEdgeInsetsMake(0, 15, 0, 0);
    addButton.contentEdgeInsets = UIEdgeInsetsMake(0, 15, 0, 0);
    [addButton setClicAction:^(UIButton *sender) {
        [weakSelf onSelctedNewFriendButton];
    }];
    [header addSubview:addButton];
    
    
    STButton * groupButton = [[STButton alloc] initWithFrame:CGRectMake(0, addButton.bottom, UIScreenWidth , 50)
                                                     title:@"群聊"
                                                titleColor:FirstTextColor
                                                 titleFont:16
                                              cornerRadius:4
                                           backgroundColor:UIColor.whiteColor
                                           backgroundImage:nil
                                                     image:[UIImage imageNamed:@"qunliao"]];
    groupButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
    groupButton.titleEdgeInsets = UIEdgeInsetsMake(0, 15, 0, 0);
    groupButton.contentEdgeInsets = UIEdgeInsetsMake(0, 15, 0, 0);
    [groupButton setClicAction:^(UIButton *sender) {
        [weakSelf onSelctedGroupButton];
    }];
    [header addSubview:groupButton];
    
    header.height = groupButton.bottom;
    self.tableView.tableHeaderView = header;
}
#pragma --mark UITableViewDataSource
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    
    return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    return 10;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    return MCFriendTableViewCell.cellHeight;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    
    return 0.01;
}
- (UIView*)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    return [UIView new];
}
- (UIView*)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
    return [UIView new];
}
- (UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    static NSString * reuseIdentifier =  @"cell";
    MCFriendTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:reuseIdentifier];
    if (!cell) {
        cell = [[MCFriendTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:reuseIdentifier];
        
    }
    return cell;
}
#pragma --mark UITableViewDelegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    [tableView deselectRowAtIndexPath:indexPath animated:NO];
}
#pragma mark --Action Method
- (void)onSelctedSerarchButton{
    
}
- (void)onSelctedNewFriendButton{
    
}
- (void)onSelctedGroupButton{
    
}
- (void)st_rightBarAction:(id)sender{
    UITapGestureRecognizer * rightTap = sender;
    STPopMenuViewController * menu = [[STPopMenuViewController alloc] initWithSize:CGSizeMake(120, 80) targetView:rightTap.view];
    menu.titlesArray = @[@"添加好友/群聊",@"创建群聊"];
    menu.itemBackgourndColor = UIColor.whiteColor;
    menu.titleColor = SecendTextColor;
    menu.lineColor = TM_lineColor;
    [menu setOnSelctedItemHandle:^(STPopMenuViewController *menuVc, NSInteger index, NSString *chosedTitle) {
        if (index == 0) {
            [self goToAddFriendSearch];
        }
    }];
    [self presentViewController:menu animated:YES completion:nil];
      
}
- (void)goToAddFriendSearch{
    MCAddFriendSearchViewController * vc = [MCAddFriendSearchViewController new];
    [vc setDidSelctedSearch:^(MCUserModel *user) {
        MCOtherPersonViewController * userVC = [MCOtherPersonViewController new];
        userVC.userModel = user;
        [self.navigationController pushViewController:userVC animated:YES];
    }];
    STNavigationController * nav = [[STNavigationController alloc] initWithRootViewController:vc];
    [self presentViewController:nav animated:YES completion:nil];

}
@end
